<template>
  <div id="basicInfo">
    <section class="part">
      <!-- <el-form :model="formData"  class="formlist" :inline="true">
        <el-form-item
          v-for="(item, index) in formList"
          :key="index"
          :label="item.label"
          :prop="item.prop">
            <el-input v-if="item.input" v-model="formData[item.prop]"></el-input>
            <el-input v-else-if="item.textarea" type="textarea" v-model="formData[item.prop]"></el-input>
            <el-date-picker v-else-if="item.date" v-model="formData[item.prop]" type="date" placeholder="选择日期">
            </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button class="postbtn" type="primary" @click="postform">提交</el-button>-->
      <div class="tableBox">
        <table class="leave">
          <tr>
            <td>法人代表</td>
            <td>
              <el-input v-model="formData.frdb"></el-input>
            </td>
            <td>注册地址</td>
            <td>
              <el-input v-model="formData.address"></el-input>
            </td>
          </tr>
          <tr>
            <td>注册资本</td>
            <td>
              <el-input v-model="formData.zczb"></el-input>
            </td>
            <td>经营期限</td>
            <td class="jyqx">
              <el-date-picker v-model="formData.periodStart" type="date" placeholder="选择起始日期"></el-date-picker>至
              <el-date-picker v-model="formData.periodEnd" type="date" placeholder="选择结束日期"></el-date-picker>
            </td>
          </tr>
          <tr>
            <td>统一社会信用代码</td>
            <td>
              <el-input v-model="formData.code"></el-input>
            </td>
            <td>注册资本币种</td>
            <td>
              <el-input v-model="formData.currency"></el-input>
            </td>
          </tr>
          <tr>
            <td>成立日期</td>
            <td>
              <el-date-picker v-model="formData.createTime" type="date" placeholder="选择日期"></el-date-picker>
            </td>
            <td>注册号</td>
            <td>
              <el-input v-model="formData.registerNum"></el-input>
            </td>
          </tr>
          <tr>
            <td>登记状态</td>
            <td>
              <el-input v-model="formData.state"></el-input>
            </td>
            <td>核准日期</td>
            <td>
              <el-date-picker v-model="formData.checkDate" type="date" placeholder="选择日期"></el-date-picker>
            </td>
          </tr>
          <tr>
            <td>所属行业</td>
            <td>
              <el-input v-model="formData.industry"></el-input>
            </td>
            <td>类型</td>
            <td>
              <el-input v-model="formData.type"></el-input>
            </td>
          </tr>
          <tr>
            <td>登记机关</td>
            <td>
              <el-input v-model="formData.djjg"></el-input>
            </td>
            <td>曾用名</td>
            <td>
              <el-input v-model="formData.usedName"></el-input>
            </td>
          </tr>
          <tr>
            <td>经营范围</td>
            <td colspan="3">
              <el-input type="textarea" v-model="formData.scope"></el-input>
            </td>
          </tr>
        </table>
        <el-button
          class="postbtn"
          v-if="(!farendaibiao && requirestatus)"
          type="primary"
          @click="postform"
        >提交</el-button>
        <el-button class="postbtn" v-else type="primary" @click="postform">修改</el-button>
      </div>
    </section>
    <section class="part" v-for="(part, partIndex) in tableList" :key="partIndex">
      <span class="tit">{{part.title}}</span>
      <el-table :data="part.data" border>
        <el-table-column
          v-for="(item, index) in part.cols"
          :key="index"
          :prop="item.prop"
          :label="item.label"
        ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="danger" size="small" @click="delateTable(scope.row, part.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-button class="postbtn" type="primary" @click="edittable(part.id)">编辑</el-button>
    </section>

    <el-dialog
      :title="'添加'+dialogtableTitle"
      class="dialogelform"
      center
      width="600px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="dialogform" label-width="236px">
        <el-form-item
          v-for="(item, index) in dialogformlist"
          :key="index"
          :label="item.label+'：'"
          :prop="item.prop"
        >
          <el-date-picker
            v-model="dialogform[item.prop]"
            type="date"
            value-format="yyyy-MM-dd"
            v-if="item.date"
            placeholder="选择日期"
          ></el-date-picker>
          <el-input v-model="dialogform[item.prop]" v-else placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="pushtable">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "basicInfo",
  data() {
    return {
      requirestatus: false,
      farendaibiao: "",
      formList: [
        { label: "法人代表", prop: "frdb", input: true },
        { label: "注册地址", prop: "address", input: true },
        { label: "注册资本", prop: "zczb", input: true },
        { label: "经营期限", prop: "periodEnd", input: true },
        { label: "统一社会信用代码", prop: "code", input: true },
        { label: "注册资本币种", prop: "person", input: true },
        { label: "成立日期", prop: "createTime", date: true },
        { label: "注册号", prop: "registerNum", input: true },
        { label: " 登记状态", prop: "state", input: true },
        { label: "核准日期", prop: "person", date: true },
        { label: "所属行业", prop: "industry", input: true },
        // { label: "类型", prop: "person", input: true },
        { label: "登记机关", prop: "djjg", input: true },
        // { label: "省市", prop: "person", input: true },
        { label: "曾用名", prop: "usedName", input: true },
        { label: "更新日期", prop: "person", date: true },
        { label: "经营范围", prop: "scope", textarea: true }
      ],
      formData: {},
      dialogform: {},
      dialogformlist: [],
      dialogFormVisible: false,
      currentid: 1, // 当前编辑的table  id
      dialogtableTitle: "",
      tableList: [
        {
          title: "企业联系方式",
          cols: [
            { label: "联系地址", prop: "address" },
            { label: "邮政编码", prop: "code" },
            { label: "联系电话", prop: "phone" }
          ],
          data: [],
          id: 1,
          url: "AdminAPI/clientUpdate/addQYLXFS",
          del: "deleteQYLXFS"
        },
        {
          id: 2,
          title: "联系人",
          cols: [
            { label: "姓名", prop: "name" },
            { label: "职务/职位", prop: "duty" },
            { label: "联系地址", prop: "address" },
            { label: "固定电话", prop: "telephone" },
            { label: "移动电话", prop: "phone" },
            { label: "电子邮箱", prop: "mail" },
            { label: "传真号码", prop: "faxNum" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addLXR",
          del: "deleteLXR"
        },
        {
          id: 3,
          title: "银行信息",
          cols: [
            { label: "账户名", prop: "accountName" },
            { label: "开户银行", prop: "openBank" },
            { label: "账号", prop: "accountNum" },
            { label: "备注", prop: "remark" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addYHXX",
          del: "deleteYHXX"
        },
        {
          id: 4,
          title: "开票信息",
          cols: [
            { label: "购买方名称", prop: "buyerName" },
            { label: "购买方地址", prop: "buyerAddress" },
            { label: "购买方电话", prop: "buyerPhone" },
            { label: "纳税人识别号", prop: "identifyNum" },
            { label: "开户银行", prop: "openBank" },
            { label: "账号", prop: "accountNum" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addKPXX",
          del: "deleteKPXX"
        },
        {
          id: 5,
          title: "重大税收违法",
          cols: [
            { label: "事件时间", prop: "eventTime", date: true },
            { label: "案件上报日期", prop: "reportTime", date: true },
            { label: "案件性质", prop: "caseNature" },
            { label: "主要违法事实", prop: "illegalFacts" },
            { label: "纳税人识别号", prop: "discernNum" },
            { label: "发布时间", prop: "releaseTime", date: true },
            {
              label: "相关法律依据及税务处理处罚情况",
              prop: "punishSituation"
            },
            { label: "纳税人名称", prop: "taxpayerName" },
            { label: "组织机构代码", prop: "orgCode" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addZDSSWF",
          del: "deleteZDSSWF"
        },
        {
          id: 6,
          title: "开庭公告",
          cols: [
            { label: "开庭时间", prop: "sessionTime", date: true },
            { label: "法院", prop: "court" },
            { label: "案由", prop: "cause" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addKTGG",
          del: "deleteKTGG"
        },
        {
          id: 7,
          title: "裁判文书",
          cols: [
            { label: "判决时间", prop: "sentenceTime", date: true },
            { label: "标题", prop: "title" },
            { label: "案由", prop: "cause" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addCPWS",
          del: "deleteCPWS"
        },
        {
          id: 8,
          title: "被执行人",
          cols: [
            { label: "发布时间", prop: "releaseTime", date: true },
            { label: "执行标的", prop: "implementTarget" },
            { label: "执行法院", prop: "implementCourt" },
            { label: "案件状态", prop: "status" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addBZXR",
          del: "deleteBZXR"
        },
        {
          id: 9,
          title: "行政处罚",
          cols: [
            { label: "事件时间", prop: "incidentTime", date: true },
            { label: "标题", prop: "title" },
            { label: "处罚部门（做出处罚决定的机关名称）", prop: "department" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addXZCF",
          del: "deleteXZCF"
        },
        {
          id: 10,
          title: "行政许可",
          cols: [
            { label: "事件时间", prop: "issueTime", date: true },
            { label: "许可事项名称", prop: "name" },
            { label: "许可内容", prop: "content" },
            { label: "许可机关", prop: "office" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addXZXK",
          del: "deleteXZXK"
        },
        {
          id: 11,
          title: "债券发行",
          cols: [
            { label: "发布时间", prop: "issueTime", date: true },
            { label: "债券简称", prop: "shortName" },
            { label: "债券类型", prop: "type" },
            { label: "实际发行量（亿）", prop: "issueNum" },
            { label: "最新评级", prop: "rate" },
            { label: "债券发行日", prop: "bondIssueDate" },
            { label: "债券摘牌日", prop: "bondDelistDate" },
            { label: "状态", prop: "state" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addZQFX",
          del: "deleteZQFX"
        },
        {
          id: 12,
          title: "评级记录",
          cols: [
            { label: "发布时间", prop: "issueTime", date: true },
            { label: "评级公司", prop: "company" },
            { label: "评级对象", prop: "rateObject" },
            { label: "评级方式", prop: "way" },
            { label: "评级日期", prop: "rateTime", date: true }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addPJJL",
          del: "deletePJJL"
        },
        {
          id: 13,
          title: "债券公告",
          cols: [
            { label: "发布时间", prop: "issueTime", date: true },
            { label: "发行人", prop: "issuer" },
            { label: "公告类型", prop: "type" },
            { label: "披露对象", prop: "disclosureObject" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addZQGG",
          del: "deleteZQGG"
        },
        // ----201905281800
        {
          id: 14,
          title: "担保",
          cols: [
            { label: "事件时间", prop: "incidentTime", date: true },
            { label: "公告方", prop: "announcementParty" },
            { label: "当事人", prop: "parties" },
            { label: "交易日期", prop: "tradeDate", date: true },
            { label: "公告日期", prop: "announcementDate", date: true }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addDB",
          del: "deleteDB"
        },
        {
          id: 15,
          title: "经营异常",
          cols: [
            { label: "列入日期", prop: "createTime", date: true },
            { label: "决定机关", prop: "office" },
            { label: "异常原因", prop: "abnormalCause" },
            { label: "移出原因", prop: "outReason" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addJYYC",
          del: "deleteJYYC"
        },
        {
          id: 16,
          title: "专利",
          cols: [
            { label: "公告日期", prop: "noticeTime", date: true },
            { label: "申请公布号", prop: "noticeNum" },
            { label: "专利名称", prop: "name" },
            { label: "专利类型", prop: "type" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addZL",
          del: "deleteZL"
        },
        {
          id: 17,
          title: "招投标",
          cols: [
            { label: "审核通过时间", prop: "releaseTime", date: true },
            { label: "地区", prop: "region" },
            { label: "标题", prop: "title" },
            { label: "公告类型", prop: "type" }
          ],
          data: [],
          url: "AdminAPI/clientUpdate/addZTB",
          del: "deleteZTB"
        }
      ]
    };
  },
  created() {
    this.getdata();
  },
  methods: {
    // 删除表格
    delateTable(row, tableid) {
      let obj = this.tableList.find((item, index) => {
        return item.id == tableid;
      });
      if (obj) {
        this.axios
          .post("AdminAPI/clientUpdate/" + obj.del, {id: row.id})
          .then(({ data }) => {
            if (data.code == 200) {
              this.$message({ message: "删除成功", type: "success" });
              this.getdata();
            }
          });
      }
    },
    edittable(id) {
      //编辑表格
      this.currentid = id;
      this.tableList.forEach(item => {
        if (id == item.id) {
          this.dialogformlist = item.cols;
          this.dialogtableTitle = item.title;
          // item.cols.forEach(col => {
          //   this.dialogform[col.prop] = ''
          // })
          this.dialogFormVisible = true;
        }
      });
    },
    postform() {
      // 提交基本信息表单
      this.formData.clientId = sessionStorage.getItem("customerId");
      this.axios
        .post("AdminAPI/clientUpdate/addGSXX", this.formData)
        .then(({ data }) => {
          if (data.code == 200) {
            this.$message({ message: "提交成功", type: "success" });
            this.getdata();
          }
        });
    },
    pushtable() {
      // 编辑后向table中添加数据
      console.log(this.dialogform);
      this.tableList.forEach(item => {
        if (this.currentid == item.id) {
          this.dialogform.clientId = sessionStorage.getItem("customerId");
          this.axios.post(item.url, [this.dialogform]).then(({ data }) => {
            if (data.code == 200) {
              // item.data.push(this.dialogform);
              this.dialogform = {};
              this.dialogFormVisible = false;
              this.getdata(); // 获取更新数据
            }
          });
        }
      });
    },
    getdata() {
      this.axios
        .get("AdminAPI/client/getCompanyInfo", {
          params: { clientId: sessionStorage.getItem("customerId") }
        })
        .then(({ data }) => {
          this.requirestatus = true;
          this.formData = data.data.businessInfo;
          this.farendaibiao = data.data.businessInfo.frdb;
          this.tableList[0].data = data.data.contactWay;
          this.tableList[1].data = data.data.contactPerson;
          this.tableList[2].data = data.data.bankInfo;
          this.tableList[3].data = data.data.billingInfo;
          this.tableList[4].data = data.data.revenueIllegal;
          this.tableList[5].data = data.data.sessionNotice;
          this.tableList[6].data = data.data.decideDoc;
          this.tableList[7].data = data.data.implementPerson;
          this.tableList[8].data = data.data.administrativePenalty;
          this.tableList[9].data = data.data.administrativeLicensing;
          this.tableList[10].data = data.data.bondIssue;
          this.tableList[11].data = data.data.ratingRecord;
          this.tableList[12].data = data.data.bondAnnouncement;
          this.tableList[13].data = data.data.guarantee;
          this.tableList[14].data = data.data.abnormalOperation;
          this.tableList[15].data = data.data.patent;
          this.tableList[16].data = data.data.bidding;
          console.log(data);
        });
    }
  }
};
</script>
<style lang="scss">
#basicInfo {
  .el-date-editor {
    width: 100%;
  }
  .formlist .el-form-item:last-child {
    width: 100%;
    .el-form-item__label {
      width: 17.5%;
    }
    .el-form-item__content {
      width: 82.5%;
    }
  }
  .postbtn {
    margin: 20px auto 0;
    display: block;
  }
  .tableBox {
    .leave {
      width: 100%;
      border-collapse: collapse;
      color: #333333;
      tr {
        td {
          min-width: 100px;
          text-align: center;
          border: 1px solid #dfdcdf;
          padding: 8px;
          &:nth-child(odd) {
            background: #fffaf3;
          }
        }
      }
    }
  }
  .jyqx {
    .el-date-editor {
      width: 46%;
    }
  }
  .dialogelform {
    .el-dialog__body {
      display: flex;
      .el-form-item {
        display: flex;
        .el-form-item__content {
          margin-left: 0 !important;
        }
      }
      // .el-form {
      //   width: auto;
      //   display: block;
      // }
      // .el-form-item__content {
      //   display: inline-block;
      //   // margin-right: 0 !important;
      // }
    }
  }
}
</style>
